home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / subntx2.zip / SUBROWSE.PRG < prev    next >
Text File  |  1990-05-24  |  4KB  |  244 lines

  1. PARAMETERS dbfname, indexname, lkey, hkey, pattern, filt_cond, tries
  2. external descend
  3.  
  4. * I thought I'd through in this kind of utility I have used to do some 
  5. * testing.  Please forgive my on-the-fly program writing style. Use this
  6. * from the C: prompt as a utility to browse a subset of a database, using
  7. * its associated (and updated) index to extract the sub index from.
  8. * SYNTAX:  subrowse <dbfname> <indexname> <lkey> <hkey> <pattern>
  9. * Notice optional "" in example.
  10. * EXAMPLE: 
  11. *
  12. *   subrowse test testindex A            && everything beginning with 'A'
  13. *   subrowse test testindex "A"          && same as above
  14. *   subrowse test testindex "A "         && everything beginning with 'A '
  15. *   subrowse test testindex A B "*THE*"  && Everything between A and B
  16. *                                           with the work "THE" somewhere
  17. *                                           in the key.
  18. *
  19. *   subrowse test testindex A B "*THE*" "lname=='Moon'"    && Same as above
  20. *                                        && but also calls _subeval() with
  21. *                                        && the condition.  Be careful its
  22. *                                        && a valid condition.
  23. *
  24. *   Thanks for your support.....
  25.  
  26. PUBLIC use_extproc
  27. public times[2]
  28.  
  29.  
  30.  
  31.  
  32. DO CLSCREEN
  33.  
  34. if pcount() < 3
  35.     ? "Usage: subrowse <dbfname>, <ntxname>, <lkey> [,<hkey> [,<pattern> [,<filt_cond>]]]"
  36.     quit
  37. endif             
  38.  
  39.  
  40. if type("hkey") == "U"
  41.     hkey = ""
  42. endif
  43.  
  44. if type("pattern") == "U"
  45.     pattern = ""
  46. endif
  47.  
  48.  
  49. if type("filt_cond") != "C"
  50.     filt_cond = ""
  51.     use_extproc = .f.
  52. else     
  53.     if filt_cond == ""
  54.         use_extproc = .f.
  55.     else
  56.         use_extproc = .t.
  57.     endif
  58.  
  59. endif
  60.  
  61.  
  62. if type("tries") != "C"
  63.     tries = 3
  64. else
  65.     tries = val(tries)
  66. endif
  67.  
  68.  
  69.  
  70. **  Uncomment this block if you want to display this info
  71. *
  72. *
  73. *?  "dbfname:     "
  74. *??  dbfname
  75. *
  76. *?  "indexname:   "
  77. *??  indexname
  78. *
  79. *?  "lkey:        "
  80. *??  lkey
  81. *
  82. *?  "hkey:        "
  83. *??  hkey
  84. *
  85. *?  "pattern:     "
  86. *??  pattern
  87. *
  88. *?  "use_extproc: " 
  89. *??  use_extproc 
  90. *?
  91. *
  92. *?  "filt_cond: " 
  93. *??  filt_cond 
  94. *?
  95. *
  96. *?  "retry count: " 
  97. *??  tries 
  98. *?
  99. *
  100. *wait
  101. *
  102. *
  103.  
  104.  
  105. dbfname = fixfile( dbfname, "dbf" )
  106.  
  107. if ! file(dbfname)
  108.     ? "Can't find: "+dbfname
  109.     quit
  110. endif
  111.  
  112.  
  113. use (dbfname) 
  114.  
  115.  
  116.  
  117.  
  118. indexname = fixfile(indexname, "ntx" )
  119. if ! file(indexname)
  120.     ? "Cant find: "+indexname
  121.     quit
  122. endif
  123.  
  124.  
  125. if file("_sub.ntx")
  126.     wait [File "_sub.ntx" already exists, do you want to overwrite? ] to yn
  127.     if upper(yn) <> "Y"
  128.         quit
  129.     endif
  130. endif
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. time1 = seconds()    
  138.  
  139. ********* HERE IT IS *************
  140. **********************************
  141.  
  142. recs = subntx( indexname, "_sub.ntx", lkey, hkey, pattern, use_extproc, tries )
  143.  
  144. **********************************
  145. **********************************
  146.  
  147. time2 = seconds()
  148. times[1] = "Total SubNtx() time: "+str( time2-time1 )          
  149.  
  150. IF recs < 0
  151.     ? "Error returned: "+str(recs)
  152.     quit
  153. endif
  154.  
  155.  
  156.  
  157.  
  158. set index to _sub
  159.  
  160. public flds[ fcount() ]
  161. afields( flds )
  162.  
  163.  
  164.  
  165. DO CLSCREEN
  166. @ 0,0 say "          Browsing " + alltrim(str(recs))+ " records.....Press <Esc> to finish...."
  167. browse()                                          
  168.  
  169.  
  170. clear
  171. ? times[1]
  172.  
  173. use
  174.  
  175. erase _sub.ntx
  176.  
  177.  
  178. *                           End of main
  179. ***************************************************************************
  180.  
  181.  
  182. FUNCTION browse
  183.  
  184.     t = 5
  185.     l = 5
  186.     b = 20
  187.     r = 75
  188.  
  189.  
  190.     @ t-1,l-1 clear to b+1,r+1
  191.     @ t-1,l-1 to b+1,r+1 double
  192.  
  193.     dbedit(t,l,b,r,flds)                                          
  194.     DO CLSCREEN
  195. return ""
  196.  
  197.  
  198.  
  199.  
  200. FUNCTION fixfile
  201.     parameters filename, ext
  202.  
  203.     if [.] $ filename
  204.         filename = substr(filename,1, at(".",filename) ) + ext
  205.     else
  206.         filename = trim(filename)+"."+ ext
  207.     endif
  208.  
  209. return filename 
  210.  
  211.  
  212.  
  213.  
  214. PROCEDURE _subeval
  215.     rec = subrec()
  216.     key = subkey()
  217.     go rec
  218.     if &FILT_COND   && global variable with a valid condition to check
  219.         reteval(.T.)
  220.     else
  221.         reteval(.F.)
  222.     endif
  223. RETURN 
  224.  
  225.  
  226.  
  227.  
  228. PROCEDURE CLSCREEN
  229. setcolor("W/B,+N/W")
  230.  
  231. @ 00,00,24,79 box replicate(chr(177),9)
  232.  
  233. return
  234.